package cn.jdy.plugins.admin;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.plugins.entity.RobotContent;
import cn.jdy.plugins.entity.RobotManager;
import cn.jdy.plugins.service.RobotContentService;
import cn.jdy.plugins.service.RobotLinksService;

@Controller
@RequestMapping("/robotResult")
public class RobotResultCtrl extends BaseCtrl {
	@Autowired
	private RobotLinksService robotLinksService;
	@Autowired
	private RobotContentService robotContentService;
	
	@RequestMapping("/list")
	@ResponseBody
	public Map<String, Object> list(RobotManager robotManager, String fromDate, String toDate, String status) {
		Map<String, Object> jsonMap = new HashMap<>();
        int count = robotLinksService.count(robotManager.getName(), status, fromDate, toDate);
        jsonMap.put("iTotalDisplayRecords", count);
        jsonMap.put("iTotalRecords", count);
        String name = robotManager.getName();
        int start = robotManager.getiDisplayStart();
        int length = robotManager.getiDisplayLength();
        jsonMap.put("dataList", robotLinksService.list(name, status, fromDate, toDate, start, length));
        return jsonMap;
	}
	
	@RequestMapping("/showDetail")
	@ResponseBody
	public RobotContent showDetail(String id) {
		return robotContentService.findOne("linkid", id);
	}
}
